package 比屋作业.day15;
import java.util.*;
public class D15_3 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        Account account=new Account();
        while(true){
        System.out.println("====欢迎使用xxxx银行存取一体机====");
        System.out.println("1.存款");
        System.out.println("2.取出");
        System.out.println("3.余额查询");
        System.out.println("4.退出");
        System.out.println("请输入您要办理的业务：");
        int choice=scanner.nextInt();

            switch (choice){
                case 1:account.saving();
                    break;
                case 2:account.get();
                    break;
                case 3:account.getRemainMony();
                    break;
                case 4:
                    System.out.println("感谢使用！");
                    scanner.close();
                    return;
                default:
                    System.out.println("无效的输入，请重新输入！");
            }
        }
    }
}
class Account{
    int remainMony=500;
    Scanner scanner=new Scanner(System.in);
    public void saving(){
        while(true){
            System.out.println("请输入存款金额：");
            int savingMony=scanner.nextInt();
            if (savingMony<0){
                System.out.println("存入到的金钱不能为负，请重新输入！");
                continue;
            }
            remainMony=savingMony+remainMony;
            System.out.println("存款成功！目前余额为"+remainMony);
            break;
        }
    }
    public void get(){
        while(true){
            System.out.println("请输入要取出的金额");
            int getMony=scanner.nextInt();
            if (getMony<0){
                System.out.println("取出金额不能为负数！");
                continue;
            }
            else if (getMony>remainMony){
                System.out.println("余额不足，请重新输入！");
                continue;
            }
            else {
                remainMony=remainMony-getMony;
                System.out.println("以取出"+getMony+"，余额为："+remainMony);
                break;
            }
        }
    }
    public void getRemainMony(){
        System.out.println("您的余额为"+remainMony);
    }
}
